#include "FenOptions.h"
#include "defines.h"

FenOptions::FenOptions() : QWidget()
{
	QSettings settings("", "Nemo");
	
	lineEditHomePage = new QLineEdit(settings.value("HomePage", QString(SETTINGS_HOME_PAGE)).toString(), this);
	boutonValider = new QPushButton("Valider", this);
	boutonAnnuler = new QPushButton("Annuler", this);
	QFormLayout *formLayout = new QFormLayout;
	formLayout->addRow(QString(tr("Page d'&accueil :")), lineEditHomePage);
	QHBoxLayout *layoutBas = new QHBoxLayout();
	layoutBas->addWidget(boutonValider);
	layoutBas->addWidget(boutonAnnuler);
	
	QGridLayout *layoutPrincipal = new QGridLayout();
	layoutPrincipal->addLayout(formLayout, 0, 0);
	layoutPrincipal->addLayout(layoutBas, 1, 0);

	setLayout(layoutPrincipal);
	setWindowFlags(Qt::SubWindow);
	setWindowTitle("Options");

	connect(boutonValider, SIGNAL(clicked()), this, SLOT(enregistrerPrefs()));
	connect(boutonAnnuler, SIGNAL(clicked()), this, SLOT(deleteLater()));
}

void FenOptions::enregistrerPrefs()
{
	QSettings settings("", "Nemo");
	
	settings.setValue("HomePage", lineEditHomePage->text());
	this->deleteLater();
}
